(function(){

    var html = document.documentElement;
    var attrName = 'design-width';
    var host = window;
    var MutationObserver = host.MutationObserver
    || host.WebKitMutationObserver
    || host.MozMutationObserver;

    function resizeView(){
        var width = html.getBoundingClientRect().width;
        var attr = html.attributes[attrName];
        var designWidth = (attr && attr.nodeValue) || 750;
        var ratio = width / designWidth;
        html.style.fontSize = (ratio * 100) + 'px';
        window.rem = ratio * 100;
    }
    var event="orientationchange"in host?"orientationchange":"resize";
    host.addEventListener(event,resizeView,false);
    host.addEventListener('pageshow',resizeView,false);
    if(MutationObserver){
        (new MutationObserver(function(mutations) {
            mutations.forEach(function(mutation){
                if(mutation.attributeName == attrName){
                    resizeView();
                }
            })
        })).observe(html, {attributes: true});
    }
    resizeView();
})();